package edu.vt.ece4564.bluetendance.students;

import javax.servlet.http.HttpServletResponse;

import edu.vt.ece4564.bluetendance.database.DatabaseConnector;

public class UserRegistrationHandler implements Runnable {
	private String className;
	private String bluetoothID;
	private String userName;
	private String bluetoothName;
	private HttpServletResponse response;

	public UserRegistrationHandler(HttpServletResponse response, String userName, String bluetoothName, String bluetoothID, String className) {
		this.userName = userName;
		this.bluetoothName = bluetoothName;
		this.bluetoothID = bluetoothID;
		this.className = className;
		this.response = response;
		this.response.setContentType("text/plain");
	}
	
	@Override
	public void run() {
		DatabaseConnector dc = DatabaseConnector.get();
		
		dc.commandText = "call SP_RegisterUser('" + className + "', '" + userName + "', '" + bluetoothID + "', '" + bluetoothName + "');";
		
		dc.executeNonQuery();
		try {
			response.getWriter().write("Your registration information was saved successfully.");
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
